package com.longteng.lesson.controller;

import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator
 * DATE : 2018/5/20
 * TIME : 14:52
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Controller
public class MyErrorController  implements ErrorController {
    /**
    * spring有一个自带的error，下面这样写，相当于覆盖了他的error，自己做实现
     * 他不是在类里面出现的异常
    * */
    @RequestMapping("/error")
    public String handleError(HttpServletRequest request){
        Object o =request.getAttribute("javax.servlet.error.status_code");
        Integer statusCode = (Integer)o;
        // 如果这里面出现异常信息，然后你没有catch住，是不是就直接扔出去? 是
        if(statusCode == HttpStatus.NOT_FOUND.value()){
            return "/errorpage/error-404";
        }else{
            return "/errorpage/error-500";
        }
    }

    public String getErrorPath() {
        return null;
    }
}
